<?php echo $this->fetch('header.html'); ?>
<script type="text/javascript">
    $(function () {
        $('#ad_form').validate({
            errorPlacement: function (error, element) {
                $(element).next('.field_notice').hide();
                $(element).after(error);
            },
            success: function (label) {
                label.addClass('right').text('OK!');
            },
            onkeyup: false,
            rules: {
                <?php if (! $this->_var['ad']['ad_pic']): ?>
                ad_pic: {
                    required: true,
                    accept: 'gif|png|jpe?g'
                },
                <?php endif; ?>
                ad_name: {
                    required: true,
                }
            },
            messages: {
                <?php if (! $this->_var['ad']['ad_pic']): ?>
                ad_pic: {
                    required: 'ad_logo_empty',
                    accept: '支持格式gif,jpg,jpeg,png'
                },
                <?php endif; ?>
                ad_name: {
                    required: 'ad_name_empty',
                }
            }
        });
    });
</script>
<div id="rightTop">
    <p>手机素材管理</p>
    <ul class="subnav">
        <li><a class="btn1" href="index.php?app=limitedtime_setting">管理</a></li>
        <li><span>编辑</span></li>
    </ul>
</div>

<div class="info">
    <form method="post" enctype="multipart/form-data" id="limitedtime_form">
        <table class="infoTable">
            <tr>
                <th class="paddingT15">
                    标题:</th>
                <td class="paddingT15 wordSpacing5" >
                    <input class="infoTableFile2" id="limitedtime_title" name="limitedtime_title" value="<?php echo $this->_var['limitedtime']['limitedtime_title']; ?>"/>
                </td>
            </tr>
            <tr>
                <th class="paddingT15">
                    选择图片:</th>
                <td class="paddingT15 wordSpacing5">
                    <input class="infoTableFile2" id="limitedtime_url" type="file" name="limitedtime_url" />
                    <label class="field_notice">支持格式gif,jpg,jpeg,png</label>
                </td>
            </tr>
            <?php if ($this->_var['limitedtime']['limitedtime_url']): ?>
            <tr>
                <th class="paddingT15">
                </th>
                <td class="paddingT15 wordSpacing5">
                    <img src="<?php echo $this->_var['limitedtime']['limitedtime_url']; ?>?<?php echo $this->_var['random_number']; ?>" class="makesmall" max_width="120" max_height="90" />
                </td>
            </tr>
            <?php endif; ?>
            <tr>
                <th class="paddingT15">
                    选择商品:</th>
                <td class="paddingT15 wordSpacing5">
                    <button class="formbtn cart-add" type="button">选择</button>
                    <div class="choose_goods" style="padding-top:20px ">
                        <?php if ($this->_var['limitedtime']['goods']): ?>
                        <?php $_from = $this->_var['limitedtime']['goods']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'bg');if (count($_from)):
    foreach ($_from AS $this->_var['bg']):
?>
                        <label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="<?php echo $this->_var['bg']['goods_id']; ?>"><?php echo $this->_var['bg']['goods_name']; ?></label><input type="checkbox" checked style="display: none" value="<?php echo $this->_var['bg']['goods_id']; ?>" name="goods"><img style="margin-right: 10px" src="templates/style/images/close.gif" onclick="dropGoods(this)" fieldname="mall_limitedtimeed" fieldid="<?php echo $this->_var['bg']['goods_id']; ?>" fieldvalue="1" title="可编辑"/>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                        <?php endif; ?>
                    </div>
                    <input id="goods_id" name="goods_id" style="display: none" value="<?php echo $this->_var['limitedtime']['goods_id']; ?>">
                </td>
            </tr>
            <tr>
                <th class="paddingT15">
                    开始时间:</th>
                <td class="paddingT15 wordSpacing5" >
                    <input class="infoTableFile2" id="start_time" type="input" name="start_time" value="<?php echo $this->_var['limitedtime']['start_time']; ?>"/>
                </td>
            </tr>
            <tr>
                <th class="paddingT15">
                    有效期至:</th>
                <td class="paddingT15 wordSpacing5" >
                    <input class="infoTableFile2" id="end_time" type="input" name="end_time" value="<?php echo $this->_var['limitedtime']['end_time']; ?>"/>
                </td>
            </tr>
            <tr>
                <th class="paddingT15">
                    排序:</th>
                <td class="paddingT15 wordSpacing5" >
                    <input class="infoTableFile2" id="sort_order" type="number" name="sort_order" value="<?php echo $this->_var['limitedtime']['sort_order']; ?>"/>
                </td>
            </tr>
            <tr>
                <th></th>
                <td class="ptb20">
                    <input class="formbtn" type="submit" name="Submit" value="提交" />
                    <input class="formbtn" type="reset" name="Submit2" value="重置" />
                </td>
            </tr>
        </table>
    </form>

    <div class = "bg-model" style="position:absolute;top:0%;left:0%;display:none;background:rgba(0,0,0,0.3);width:100%;height:100%;position:fixed;z-index:9999">
        <iframe src="index.php?app=goods&act=iframe" id="goods_page" width="90%" height="90%"></iframe>
    </div>
</div>
<?php echo $this->fetch('footer.html'); ?>
<script>
    var goods_id = '';
    $(function () {
    })
    $(".cart-add").click(function () {
        $("iframe").contents().find(".checkitem:checked");
        $("iframe").contents().find(".checkitem:checked").each(function () {
            $(this).removeAttr('checked');
        })
        $("iframe").contents().items = '';
        $(".bg-model").fadeTo(300,1)
        //隐藏窗体的滚动条
        $("body").css({"overflow": "hidden"});
    });

    //模态框OK按钮点击事件
    $(".bg-model-ok").click(function () {
        $(".bg-model").hide();
        //显示窗体的滚动条
        $("body").css({"overflow": "visible"});
    }).hover(function () {
        $(this).css({"backgroundColor": "#8CC8C8"});
    }, function () {
        $(this).css({"backgroundColor": "#8CD4E6"});
    });
    $("#enter").click(function () {
        var items = '';
        var name = '';
        $('.checkitem:checked').each(function(){
            items += this.value + ',';
            name += $(this).attr('attr-name') + ','
        });
        items = items.substr(0, (items.length - 1));
        name = name.substr(0, (name.length - 1));
        var items_arr = items.split(',');
        var name_arr = name.split(',');
        for(var i in items_arr){
            $(".choose_goods").append('<label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+name_arr[i]+'</label><input type="checkbox" checked style="display: none" value="'+items_arr[i]+'" name="goods"><img style="margin-right: 10px" src="templates/style/images/close.gif" onclick="dropGoods(this' +
                ')" fieldname="mall_recommended" fieldid="<?php echo $this->_var['goods']['goods_id']; ?>" fieldvalue="1" title="可编辑"/>');
        }
        $('#goods_id').val($('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(','));
        $(".bg-model").hide();
        //显示窗体的滚动条
        $("body").css({"overflow": "visible"});
    })
    function dropGoods(obj) {
        $(obj).prev().remove();
        $(obj).prev().remove();
        $(obj).remove()
        console.log($('#goods_id').val())
        $('#goods_id').val($('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(','));
        console.log($('#goods_id').val())
    }

</script>
